package com.huluobo.a2203kotlindouyindemo.adapter

import android.animation.ObjectAnimator
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2203kotlindouyindemo.R
import com.huluobo.a2203kotlindouyindemo.utils.ImageUtils
import com.huluobo.base.bean.VideoBean
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

/**
 *  Created by LC on 2024/7/3.
 */
class VIdeoAdapter(list: MutableList<VideoBean>) :
    BaseQuickAdapter<VideoBean, BaseViewHolder>(R.layout.item_video, list) {
    override fun convert(holder: BaseViewHolder, item: VideoBean) {
        val player = holder.getView<StandardGSYVideoPlayer>(R.id.item_video_gsyPlayer)
        player.backButton.visibility = View.GONE
        player.setUp(item.videopath, true, "")

        //地址
        holder.setText(R.id.item_video_address_tv, item.address)
        //作者
        holder.setText(R.id.item_video_authname_tv, item.authname)
        //描述
        holder.setText(R.id.item_video_caption_tv, item.caption)
        //跑马灯
        holder.setText(R.id.item_video_pao_tv, "${item.authname}的原创作品")

        //头像
        ImageUtils.loadCircleImage(context, item.headpath, holder.getView(R.id.item_video_header_iv))
        //关注状态
        if (item.guanzhu == 0) {
            holder.getView<ImageView>(R.id.item_video_add_iv).visibility = View.VISIBLE
        } else {
            holder.getView<ImageView>(R.id.item_video_add_iv).visibility = View.GONE
        }
        //点赞状态
        if (item.dianzan == 0) {
            holder.setImageResource(R.id.item_video_like_iv, R.drawable.ic_xihuan)
        } else {
            holder.setImageResource(R.id.item_video_like_iv, R.drawable.ic_xihuanred)
        }
        //点赞数量
        holder.setText(
            R.id.item_video_like_count_tv,
            if (item.like_count < 10000) item.like_count.toString() else "${item.like_count / 10000}W"
        )
        //评论数量
        holder.setText(R.id.item_video_comment_count_tv, "3.5W")
        //收藏数量
        holder.setText(R.id.item_video_follow_count_tv, "2.5W")
        //分享数量
        holder.setText(R.id.item_video_share_count_tv, "4.5W")
        //碟片动画
        val musicPlayerIv = holder.getView<ImageView>(R.id.item_video_music_player_iv)
        ImageUtils.loadCircleImage(context, item.headpath, musicPlayerIv)

        val animator = ObjectAnimator.ofFloat(musicPlayerIv, "Rotation", 0f, 360f)
        animator.duration = 3000
        animator.repeatCount = -1
//        animator.interpolator = LinearInterpolator()
        animator.start()
    }
}